﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.fountain {
    import flash.events.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class TreeMediator extends AbstractViewMediator {

		[Inject]
        public var session:SessionModel;
		[Inject]
        public var language:LanguageModel;
        private var _bubbleId:String = "treeBubble";
        private var _bubbleText:String = "";

        override public function onRegister():void{
            super.onRegister();
            this.view.mouseChildren = false;
            addContextListener(EventConstants.HIDE_TREE, this.onHideTree);
            addContextListener(EventConstants.SHOW_TREE, this.onShowTree);
            addContextListener(EventConstants.SET_TREE_SYMBOL, this.onSetSymbol);
            addContextListener(EventConstants.SET_TREE_STATE, this.onSetState);
            addContextListener(EventConstants.UPDATE_TREE_BUBBLE, this.onUpdateBubble);
            addContextListener(EventConstants.HAS_FOUNTAIN, this.onHasFountain);
            this.updateMouseHandlers();
            this.view.visible = false;
        }
        private function onHasFountain(_arg1:Event):void{
            this.updateMouseHandlers();
        }
        private function updateMouseHandlers():void{
            this.view.useHandCursor = (this.view.mouseEnabled = (this.view.buttonMode = this.session.hasFountain));
            var _local1:Function = (this.session.hasFountain) ? eventMap.mapListener : eventMap.unmapListener;
            _local1(this.view, MouseEvent.CLICK, this.onClick);
            _local1(this.view, MouseEvent.MOUSE_OVER, this.onMouseOver);
            _local1(this.view, MouseEvent.MOUSE_OUT, this.onMouseOut);
        }
        private function onShowTree(_arg1:Event):void{
            this.view.visible = (this.view.useHandCursor = (this.view.mouseEnabled = (this.view.buttonMode = true)));
            this.view.alpha = 1;
        }
        private function onHideTree(_arg1:Event):void{
            this.view.visible = (this.view.useHandCursor = (this.view.mouseEnabled = (this.view.buttonMode = false)));
            this.view.alpha = 0;
        }
        private function onUpdateBubble(_arg1:InfoEvent):void{
            var _local2:int = int(_arg1.info);
            var _local3:String = ((_local2)<0) ? "fountain_ready_to_harvest" : "fountain_ready_in_time";
            var _local4:String = TimeUtils.secondsToHoursMinSec(_local2);
            this._bubbleText = this.language.getTextByKey(_local3, {time:_local4});
            this.view.bubbleTime = this._bubbleText;
        }
        private function onSetSymbol(_arg1:InfoEvent):void{
            this.view.symbol = _arg1.id;
        }
        private function onSetState(_arg1:InfoEvent):void{
            this.view.state = _arg1.id;
        }
        private function onClick(_arg1:MouseEvent):void{
            dispatch(new Event(EventConstants.HARVEST_SYMBOL));
        }
        private function onMouseOver(_arg1:MouseEvent):void{
            var _local2:InfoEvent;
            if (this._bubbleText){
                this.view.bubbleTime = this._bubbleText;
                _local2 = new InfoEvent(EventConstants.SHOW_FRONT_BUBBLE, this._bubbleId, this.view.bubble);
                dispatch(_local2);
            };
        }
        private function onMouseOut(_arg1:MouseEvent):void{
            var _local2:InfoEvent = new InfoEvent(EventConstants.HIDE_FRONT_BUBBLE, this._bubbleId);
            dispatch(_local2);
        }
        private function get view():TreeView{
            return ((viewComponent as TreeView));
        }

    }
}//package net.wooga.pets.views.fountain 
